<template>
  <!-- 委外案件查询 -->
  <section class="page query-case-out-record">
    <data-form :model="searchModel" @onSearch="refreshData" :page="pageService" @handleResetForm='handleResetForm'>
      <template slot="inputs">
        <el-form-item label="借据号" prop="caseNumber">
          <el-input v-model="searchModel.caseNumber"></el-input>
        </el-form-item>
          <el-form-item label="批次号" prop="outBatch">
          <el-input v-model="searchModel.outBatch"></el-input>
        </el-form-item>
            <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="searchModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="searchModel.idCard"></el-input>
        </el-form-item>
        <el-form-item label="委外方" prop="outsourceId">
          <!-- <el-select v-model="searchModel.outsourceId" placeholder="请选择" clearable>
            <el-option v-for="item in outSourceList" :key="item.id" :label="item.outsName" :value="item.id"></el-option>
          </el-select> -->
          <select-department :specialOptions="specialOptions" v-model="searchModel.outsourceId"></select-department>
        </el-form-item>
         <el-form-item label="委外时间" prop="caseTurnTime">
          <el-date-picker type="daterange" :editable="false" v-model="searchModel.outTime" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
          <el-form-item label="委外结束时间" prop="caseTurnTime">
          <el-date-picker type="daterange" :editable="false" v-model="searchModel.outEndDate" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
      </template>
    </data-form>

    <data-box :data="dataSet" @onPageChange="refreshData" :page="pageService">
        <template slot="columns">
        <!--数据列区域-->
         <el-table-column prop="outBatch" label="批次号" :min-width="$helper.getColumnWidth(5)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="caseNumber" label="借据号" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="idCard" label="身份证号码" :formatter="(row)=>$filter.encryptIDCardFour(row.idCard)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="overdueAmount" label="逾期金额" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="outsourceName" label="委外方" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip></el-table-column>
         <el-table-column prop="outerBeginDate" label="委外开始时间" :formatter="(row) => $filter.dateFormat(row.outerBeginDate)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
            </el-table-column>
        <el-table-column prop="outerEndDate" label="委外结束时间" :formatter="(row) => $filter.dateFormat(row.outerEndDate)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
            </el-table-column>         
        </template>
    </data-box>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { PageService } from "~/utils/page.service";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import { SortService } from "~/utils/sort.service";
import NumberRange from "~/components/common/number-range.vue";
import { SynthesizeQueryService } from "~/services/domain-service/synthesize-query.service";
import { OpenExecutionData } from "~/config/types";
import { Mutation, Getter, namespace, State } from "vuex-class";
import SelectDepartment from "~/components/business-component/select-department.vue";
import { OutsourceService } from "~/services/domain-service/outsource.service";
import { CommonService } from "~/utils/common.service";
const CollectionExecutionModule = namespace("collection-execution");
@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    NumberRange,
    SelectDepartment
  }
})
export default class QueryCaseOutRecord extends Vue {
  @Dependencies(PageService) private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;
  @Dependencies(SynthesizeQueryService)
  private synthesizeQueryService: SynthesizeQueryService;
  @Dependencies(OutsourceService) private outsourceService: OutsourceService;

  @CollectionExecutionModule.Action private openCollectionExecution;
  @State private outSourceList;

  private searchModel: any = {
    caseNumber: "",
    outBatch: "",
    outsourceId: "",
    personalName: "",
    idCard: "",
    outEndDate: [],
    outTime: []
  };

  private dataSet: any[] = [];
  private specialOptions:any[] = []

  private refreshData() {
    this.synthesizeQueryService
      .queryCaseOutRecords(this.searchModel, this.pageService)
      .subscribe(data => (this.dataSet = data));
  }
  //获取委外部门不包括律所
  private getOuterSource() {
    this.outsourceService.getOuterSource().subscribe(
      data =>{ this.specialOptions = CommonService.generateTreeData(data, {
        keyName: 'id',
        parentKeyName: 'parentId'
      })
      // data =>{console.log(data,"data")
    })
  }

  private mounted() {
    this.refreshData();
    this.getOuterSource();
  }

  private handleResetForm() {
    this.searchModel.outEndDate = { max: "", min: "" };
    this.searchModel.outTime = { max: "", min: "" };
  }
}
</script>
<style lang="less">
</style>
